package com.hd.trans.ui.adapter.vm

import android.view.View
import android.view.ViewGroup
import com.biubiu.universaladapter.base.vm.DbViewModule
import com.hd.trans.R
import com.hd.trans.databinding.VmSpaceBinding
import com.hd.trans.utils.ScreenUtil

class SpaceVm : DbViewModule<Any, VmSpaceBinding> {

    var height = 0
        set(value) {
            if (field != value) {
                field = value
                notifyItemChanged(0, "updateSize")
            }
        }

    var width = ViewGroup.LayoutParams.MATCH_PARENT
        set(value) {
            if (field != value) {
                field = value
                notifyItemChanged(0, "updateSize")
            }
        }

    var contentView: View? = null
        private set

    constructor(height: Int = ScreenUtil.dp2px(30f)) : super(R.layout.vm_space) {
        setData(Any())
        this.height = height
    }

    constructor(width:Int,height: Int) : super(R.layout.vm_space) {
        setData(Any())
        this.width = width
        this.height = height
    }

    override fun onBindData(dataBinding: VmSpaceBinding, data: Any, dataPosition: Int, layoutPosition: Int, payloads: List<*>) {
        onBindData(dataBinding,data,dataPosition,layoutPosition)
    }

    override fun onBindData(dataBinding: VmSpaceBinding, data: Any, dataPosition: Int, layoutPosition: Int) {
        contentView = dataBinding.space
        dataBinding.space.layoutParams.width = width
        dataBinding.space.layoutParams.height = height
        dataBinding.space.requestLayout()
    }

    override val spanCount: Int
        get() = 1
}